<?php

namespace fast;



use think\Db;
use addons\shopro\library\commission\Config;

use think\Exception;
use addons\shopro\model\User;

/**
 * Http 请求类
 */
class Feiyong
{

    /**
     * 发送一个POST请求
     * @param string $url     请求URL
     * @param array  $params  请求参数
     * @param array  $options 扩展参数
     * @return mixed|string
     */
    public static function add($orderId,$user_id)
    {
        
        $map['order_id'] = $orderId;
        $list = Db::table('fa_pifa_orderitem')->where($map)->select();

        $user = Db::table('fa_user')->find($user_id);



        // if ($user['group_id'] != 3 && $user['group_id'] != 6) {
        //    return;
        // }


        $invinfo = [];

        if (!empty($user['inv_id'])) {
            $invinfo = Db::table('fa_user')->find($user['inv_id']);
        }

        foreach ($list as $key => $value) {
           $goods_item = Db::table('fa_pifa_goodsitem')->find($value['goods_item_id']);

           if (empty($goods_item)) {
                continue;
           }
            $insdata = [];
            $insdata['user_id'] = $user_id;
            $insdata['goods_id'] = $goods_item['goods_id'];
            $insdata['order_id'] = $orderId;
            $insdata['order_item_id'] = $orderId;
            $insdata['goods_item_id'] = $value['goods_item_id'];
            $insdata['price'] = $value['feiyong'];
            $insdata['num'] = $value['goods_num'];
            $insdata['time'] = date('Y-m-d H:i:s');
            $insdata['state'] = '1';
            Db::table('fa_pifa_fenyong')->insert($insdata);



            // switch ($user['group_id']) {
            //     //经销商
            //     case 3:
            //        $insdata = [];
            //        $insdata['user_id'] = $user_id;
            //        $insdata['goods_id'] = $goods_item['goods_id'];
            //        $insdata['order_id'] = $orderId;
            //        $insdata['order_item_id'] = $orderId;
            //        $insdata['goods_item_id'] = $value['goods_item_id'];
            //        $insdata['price'] = bcmul($value['goods_num'],$goods_item['b_price'],2);
            //        $insdata['num'] = $value['goods_num'];
            //        $insdata['time'] = date('Y-m-d H:i:s');
            //        $insdata['state'] = '1';

            //        Db::table('fa_pifa_fenyong')->insert($insdata);
            //     break;

            //     //门店
            //     case 6:
            //         $insdata = [];
            //         $insdata['user_id'] = $user_id;
            //         $insdata['order_item_id'] = $orderId;
            //         $insdata['goods_item_id'] = $value['goods_item_id'];
            //         $insdata['goods_id'] = $goods_item['goods_id'];
            //         $insdata['goods_item_id'] = $goods_item['id'];
            //         $insdata['price'] = bcmul($value['goods_num'],$goods_item['c_price'],2);
            //         $insdata['num'] = $value['goods_num'];
            //         $insdata['time'] = date('Y-m-d H:i:s');
            //         $insdata['state'] = '1';
            //         Db::table('fa_pifa_fenyong')->insert($insdata);

            //         if (!empty($invinfo) && $invinfo['group_id'] == 3) {
            //             $insdata = [];
            //             $insdata['user_id'] = $user_id;
            //             $insdata['order_item_id'] = $orderId;
            //             $insdata['goods_item_id'] = $value['goods_item_id'];
            //             $insdata['goods_id'] = $goods_item['goods_id'];
            //             $insdata['goods_item_id'] = $goods_item['id'];
            //             $insdata['num'] = $value['goods_num'];
            //             $insdata['price'] = bcmul($value['goods_num'],$goods_item['b_price'],2);
            //             $insdata['state'] = '1';
            //              $insdata['time'] = date('Y-m-d H:i:s');
            //             Db::table('fa_pifa_fenyong')->insert($insdata);
            //         }

            //     break;
                
              
            // }


        }

        
    }





    
       

  
}
